<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人中心</title>
    <style>
        .warning-row {
            background: oldlace;
        }

        .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>
<div id="app">
    <el-row>
        <el-button type="primary" plain @click="goToChange">切换账号</el-button>
        <el-button type="primary" plain @click="openPage">我要寄快递</el-button>
        <el-button type="primary" plain @click="startToGet">我要取件</el-button>
        <el-button type="primary" plain @click="addMoney">充值^_^</el-button>
        <el-button type="primary" plain @click="getCoupon">领优惠卷</el-button>
        <el-button type="primary" plain @click="OpenMyNew">我的消息盒子</el-button>
    </el-row>
    <h2>欢迎您 </h2>
    <template>
        <div class="user-profile">
            <el-card class="user-profile-card">
                <div slot="header" class="clearfix">
                    <span class="user-profile-title">用户信息</span>
                </div>
                <el-row class="user-profile-row">
                    <el-col :span="8" class="user-avatar-col">
                        <div class="avatar-uploader">
                            <el-avatar shape="square" :size="120" :src="user.imagPath" class="avatar"></el-avatar>
                        </div>
                    </el-col>
                    <el-col :span="16">
                        <el-form label-width="80px" class="user-info-form">
                            <el-form-item label="用户名：">
                                <span>{{ user.userName }}</span>
                            </el-form-item>
                            <el-form-item label="邮箱：">
                                <span>{{ user.emailAddress }}</span>
                            </el-form-item>
                            <el-form-item label="电话：">
                                <span>{{ user.phone }}</span>
                            </el-form-item>
                            <el-form-item label="默认收货地址：">
                                <span>{{ user.defaultGetAddress }}</span>
                            </el-form-item>
                            <el-form-item label="默认送货地址：">
                                <span>{{ user.defaultSendAddress }}</span>
                            </el-form-item>
                            <el-form-item label="余额：">
                                <span>{{ user.nowMoney }}</span>
                            </el-form-item>

                        </el-form>
                    </el-col>
                </el-row>
                <el-button type="primary" icon="el-icon-edit" circle  @click="startUpdate"></el-button>
            </el-card>
        </div>
    </template>
    <el-form :inline="true" :model="order" class="demo-form-inline">

        <el-form-item label="订单编号">
            <el-input v-model="order.onlyId" placeholder="请输入您想要查找的订单号"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button icon="el-icon-search"  @click="onSubmit" circle></el-button>
        </el-form-item>
    </el-form>
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
        <el-submenu index="1">
            <template slot="title">我的订单</template>
            <el-menu-item index="1-1">待取订单</el-menu-item>
            <el-menu-item index="1-2">全部订单</el-menu-item>
        </el-submenu>
        <el-menu-item index="2"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
    </el-menu>
    <div class="line"></div>
    <!-- 根据用户选择显示订单 -->
    <el-table v-if="activeIndex === '1-1'" :data="waitingOrders" border style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="onlyId" label="订单编号"></el-table-column>
        <el-table-column prop="goodInfo" label="货物信息" align="center"></el-table-column>
        <el-table-column prop="receivePhone" label="接收人电话" align="center"></el-table-column>
        <el-table-column prop="startTime" label="下单时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="取出时间" align="center" ></el-table-column>
        <el-table-column v-if="false" prop="transportId" ></el-table-column>
        <el-table-column  label="状态" align="center" >未取出</el-table-column>
        <el-table-column align="center" label="操作">
            <template slot-scope="scope">
                <el-row>
                    <el-button type="primary" @click="openDialog(scope.row)">查看取件码和位置</el-button>
                    <el-button type="primary" @click="startToTalk(scope.row)">联系快递员</el-button>
                </el-row>
            </template>
        </el-table-column>
        <!-- 其他列 -->
    </el-table>
    <el-table v-else-if="activeIndex === '1-2'" :data="allOrders" border style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="onlyId" label="订单编号"></el-table-column>
        <el-table-column prop="goodInfo" label="货物信息" align="center"></el-table-column>
        <el-table-column prop="receivePhone" label="接收人电话" align="center"></el-table-column>
        <el-table-column prop="startTime" label="下单时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="取出时间" align="center" ></el-table-column>
        <el-table-column v-if="false" prop="transportId" ></el-table-column>
        <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="rowScope">
                <span v-if="rowScope.row.status === 0">未派送</span>
                <span v-if="rowScope.row.status === 1">寄件中</span>
                <span v-if="rowScope.row.status === 2">未取出</span>
                <span v-if="rowScope.row.status === 3">已取出</span>
            </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
            <template slot-scope="scope">
                <el-row>
                    <el-button type="primary" @click="startToTalk(scope.row)">联系快递员</el-button>
                </el-row>
            </template>
        </el-table-column>
        <!-- 其他列 -->
    </el-table>
    <!-- 分页工具条 -->
    <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange"
                   :current-page="currentPage" :page-sizes="[5, 10, 15, 20]" :page-size="pageSize"
                   layout="total, sizes, prev, pager, next, jumper" :total="totalCount">
    </el-pagination>

    <el-menu :default-active="Index" class="el-menu-demo" mode="horizontal" @select="handleSelect2">
        <el-submenu index="1">
            <template slot="title">我的寄件订单</template>
            <el-menu-item index="1-1">寄件中的订单</el-menu-item>
            <el-menu-item index="1-2">全部寄件订单</el-menu-item>
        </el-submenu>
    </el-menu>
    <div class="line"></div>
    <!-- 根据用户选择显示订单 -->
    <el-table v-if="Index === '1-1'" :data="allUnSendOrders" border style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="onlyId" label="订单编号"></el-table-column>
        <el-table-column prop="goodInfo" label="货物信息" align="center"></el-table-column>
        <el-table-column prop="receivePhone" label="接收人电话" align="center"></el-table-column>
        <el-table-column prop="startTime" label="下单时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="取出时间" align="center" ></el-table-column>
        <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="rowScope">
                <span v-if="rowScope.row.status === 0">未派送</span>
                <span v-if="rowScope.row.status === 1">寄件中</span>
                <span v-if="rowScope.row.status === 2">未取出</span>
                <span v-if="rowScope.row.status === 3">已取出</span>
            </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
            <template slot-scope="scope">
                <el-row>
                    <el-button type="primary" @click="supportComment(scope.row)">联系快递员</el-button>
                </el-row>
            </template>
        </el-table-column>
        <!-- 其他列 -->
    </el-table>
    <el-table v-else-if="Index === '1-2'" :data="allSendOrders" border style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="onlyId" label="订单编号"></el-table-column>
        <el-table-column prop="goodInfo" label="货物信息" align="center"></el-table-column>
        <el-table-column prop="receivePhone" label="接收人电话" align="center"></el-table-column>
        <el-table-column prop="startTime" label="下单时间" align="center"></el-table-column>
        <el-table-column prop="endTime" label="取出时间" align="center" ></el-table-column>
        <el-table-column prop="status" label="状态" align="center">
            <template slot-scope="rowScope">
                <span v-if="rowScope.row.status === 0">未派送</span>
                <span v-if="rowScope.row.status === 1">寄件中</span>
                <span v-if="rowScope.row.status === 2">未取出</span>
                <span v-if="rowScope.row.status === 3">已取出</span>
            </template>
        </el-table-column>
        <el-table-column align="center" label="操作">
            <template slot-scope="scope">
                <el-row>
                    <el-button type="primary" @click="startToTalk(scope.row)">联系快递员</el-button>
                </el-row>
            </template>
        </el-table-column>
        <!-- 其他列 -->
    </el-table>
    <!-- 分页工具条 -->
    <el-pagination  @size-change="handleSizeChange2" @current-change="handleCurrentChange2"
                    :current-page="currentPage2" :page-sizes="[5, 10, 15, 20]" :page-size="pageSize2"
                    layout="total, sizes, prev, pager, next, jumper" :total="totalCount2">
    </el-pagination>
    <el-dialog
            title="取件提示"
            :visible.sync="dialogVisible"
            width="30%"
    >
        <span>取件码：{{ receiveAddressAndGetWord.getWord }}</span>
        <span>取件地址：{{ receiveAddressAndGetWord.getAddress }}号柜</span>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="closeDialog">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="搜索结果" :visible.sync="dialogTableVisible">
        <el-table :data="selectResultOrder"   >
            <el-table-column property="onlyId" label="唯一标签" ></el-table-column>
            <el-table-column property="goodInfo" label="货物消息" ></el-table-column>
            <el-table-column property="transportId" label="快递员的id"></el-table-column>
            <el-table-column property="startTime" label="下单的时间"></el-table-column>
            <el-table-column property="endTime" label="取出时间"></el-table-column>
            <el-table-column property="getWord" label="取件码"></el-table-column>
            <el-table-column property="receivePhone" label="接收电话"></el-table-column>
            <el-table-column property="fromUserId" label="寄件人Id"></el-table-column>
        </el-table>
    </el-dialog>


    <el-dialog title="寄件信息填空" :visible.sync="dialogFormVisible">
        <el-row>寄一次件需要15块钱，如果使用优惠卷可以便宜10块钱呢！！！</el-row>
        <el-form :model="sendOrder" :rules="sendOrderRules" ref="sendOrderForm" label-width="120px">
            <el-form-item label="货物信息" prop="goodInfo">
                <el-input v-model="sendOrder.goodInfo" placeholder="请输入货物信息"></el-input>
            </el-form-item>
            <el-form-item label="寄送的目标地址" prop="receiveAddress">
                <el-input v-model="sendOrder.receiveAddress" placeholder="请输入寄送的目标地址"></el-input>
            </el-form-item>
            <el-form-item label="快递的起送地址" prop="sendAddress">
                <el-input v-model="sendOrder.sendAddress" placeholder="请输入快递的起送地址"></el-input>
            </el-form-item>
            <el-form-item label="接收人的电话" prop="receivePhone">
                <el-input v-model="sendOrder.receivePhone" placeholder="请输入接收人的电话"></el-input>
            </el-form-item>
            <el-form-item label="现在的优惠卷数量：">
                <span>{{ couponCount }}</span>
            </el-form-item>
            <template>
                <el-checkbox v-model="checked" v-if="couponCount>0">使用一张优惠卷</el-checkbox>
            </template>
        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="startSend('sendOrderForm')">确 定</el-button>
        </div>
    </el-dialog>




    <el-dialog title="取件信息填空" :visible.sync="getDialogFromVisible">
        <el-form :model="occupy" :rules="sendOrderRules" ref="OccupyForm" label-width="120px">
            <el-form-item label="取件的货物柜" prop="getAddress">
                <el-input v-model="occupy.getAddress" placeholder="请输入要取件的货柜"></el-input>
            </el-form-item>
            <el-form-item label="取件码" prop="getWord">
                <el-input v-model="occupy.getWord" placeholder="请输入取件码"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="getDialogFromVisible = false">取 消</el-button>
            <el-button type="primary" @click="startGet('OccupyForm')">确 定 取 件</el-button>
        </div>
    </el-dialog>

    <el-dialog title="个人信息修改" :visible.sync="updateDialog">
        <el-form :model="user" label-width="120px">
            <el-form-item label="用户名：" prop="userName">
                <el-input v-model="user.userName" placeholder="请输入新的用户名"></el-input>
            </el-form-item>
            <el-form-item label="电话：" prop="phone">
                <el-input v-model="user.phone" placeholder="请输入新电话号码"></el-input>
            </el-form-item>
            <el-form-item label="默认的收货地址：" prop="defaultGetAddress">
                <el-input v-model="user.defaultGetAddress" placeholder="请输入新的收货地址"></el-input>
            </el-form-item>
            <el-form-item label="默认的送货地址：" prop="defaultSendAddress">
                <el-input v-model="user.defaultSendAddress" placeholder="请输入新的送货地址"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="updateDialog = false">取 消</el-button>
            <el-button type="primary" @click="Update()">确 定</el-button>
        </div>
    </el-dialog>


    <el-dialog title="充值" :visible.sync="moneyDialog">
        <el-row>五块钱太少了，还是充值一个648比较方便^_^</el-row>
        <el-row>
            <el-button type="primary" plain @click="addLittleMoney">只充值5块钱(@_@)</el-button>
            <el-button type="primary" plain @click="addMuchMoney">充值一个648(＾▽＾)</el-button>
        </el-row>
    </el-dialog>


    <el-dialog title="兑换码框" :visible.sync="couponDialog">
        <el-row>规则：输入好友的兑换码就可以为其增加一张优惠卷，一个用户只能为同一个好友增加一张卷</el-row>
        <el-row>
            <el-input v-model="onlyIdOfOthers" placeholder="请输入您好友的兑换码"></el-input>
            <el-button type="success" plain  @click="addCoupon" >提交</el-button>
        </el-row>
        <el-row>
        <el-button type="primary" plain @click="HaveALook">{{ hasCoupon ? '查看我的兑换码' : '生成兑换码并免费领一张卷' }}</el-button>
        </el-row>
    </el-dialog>

    <el-dialog
            title="查看兑换码"
            :visible.sync="onlyIdDialog"
            width="30%"
    >
        <span>兑换码：{{ couponOnlyId }}</span>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="stopLook">确 定</el-button>
      </span>
    </el-dialog>



    <el-dialog title="我的消息" :visible.sync="newBoxDialog">
        <el-table :data="newBox"   >
            <el-table-column property="onlyId" label="订单编号" ></el-table-column>
            <el-table-column property="context" label="消息"></el-table-column>
            <el-table-column property="time" label="时间"></el-table-column>
        </el-table>
    </el-dialog>



</div>

<script src="js/vue.js"></script>
<script src="element-ui/lib/index.js"></script>
<link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
<script src="js/axios-0.18.0.js"></script>

<script src="js/jquery-2.1.1.min.js"></script>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                order:{
                    onlyId:'',
                    goodInfo:'',
                    status:'',
                    startTime:'',
                    receivePhone:'',
                    endTime:'',
                    getWord:'',
                    transportId:'',
                    fromUserId:'',
                    toUserId:''
                },
                sendOrder:{
                    onlyId:'',
                    goodInfo:'',
                    status:'',
                    startTime:'',
                    receivePhone:'',
                    endTime:'',
                    getWord:'',
                    transportId:'',
                    fromUserId:'',
                    toUserId:'',
                    sendAddress:'',
                    receiveAddress:''
                },
                log:false,
                DialogVisible:false,
                dialogFormVisible:false,
                pageSize: 5,
                totalCount: 1,
                currentPage: 1,
                user:{
                    id:'',
                    userName:'',
                    identity:'',
                    phone:'',
                    emailAddress:'',
                    nowMoney:'',
                    imagPath:'',
                    defaultGetAddress:'',
                    defaultSendAddress:''
                },
                receiveAddressAndGetWord:{
                  getAddress:'',
                  getWord:''
                },
                waitingOrders: [], // 待取订单列表数据
                allOrders: [], // 全部订单列表数据
                activeIndex:'1-2',
                dialogVisible:false,
                selectResultOrder:[],


                occupy:{
                    onlyId:'',
                    getWord:'',
                    getAddress:'',
                    status:'',
                    fromUserId:'',
                },

                Index:'1-2',
                allSendOrders:[],
                allUnSendOrders:[],
                pageSize2: 5,
                totalCount2: 1,
                currentPage2: 1,

                dialogTableVisible:false,
                getDialogFromVisible:false,
                updateDialog:false,
                moneyDialog:false,
                requireMoney:'',
                couponOnlyId:'',
                couponCount:0,
                hasCoupon:false,
                couponDialog:false,
                onlyIdDialog:false,
                onlyIdOfOthers:'',
                checked: false,
                newBox:[],
                newBoxDialog:false,

            }
        },
        mounted() {
            // 初始化加载数据
            this.fetchWaitingOrders();
            this.fetchAllOrders();
            this.selectUserInfo();
            this.selectAllSendingOrderByCondition();
            this.selectAllUnSendOrderByCondition();
            this.selectCouponInfo();
            this.selectCountOfCoupon();

        },
        computed: {
            totalPages() {
                // 计算总页数
                return Math.ceil(this.totalCount / this.pageSize);
            }
        },
        methods: {

            handleSizeChange(val) {
                this.pageSize = val;
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                if (this.activeIndex === '1-1') {
                    this.fetchWaitingOrders();
                } else if (this.activeIndex === '1-2') {
                    this.fetchAllOrders();
                }

            },
            selectCouponInfo(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Coupon/hasCoupon" )
                    .then((resp) => {
                       if(resp.data==='no'){
                           _this.hasCoupon=false;
                       }else{
                           _this.hasCoupon=true;
                           _this.couponOnlyId=resp.data;
                       }
                    })
                    .catch((error) => {
                        console.error(error);
                    });

            },
            selectCountOfCoupon(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Coupon/selectCountOfCoupon" )
                    .then((resp) => {
                        _this.couponCount=resp.data;
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            // 获取待取订单数据
            fetchWaitingOrders() {

                var _this=this
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/selectAllUnGetOrder?"+"CurrentPage="+this.currentPage+"&PageSize="+this.pageSize+""  )
                    .then(resp => {
                        _this.waitingOrders = [];
                        if (typeof resp.data === 'object' && resp.data!== null){
                            _this.waitingOrders.push(resp.data);}else{
                            // 使用split方法将字符串按照"}"分割成数组
                            const responseDataArray = resp.data.split('}').map(item => {
                                if (item) return JSON.parse(item + '}');
                                else return null;
                            }).filter(item => item !== null);

                            // 根据数组长度判断是否为单个对象或多个对象组成的数组
                            if (responseDataArray.length === 1) {
                                // 如果数组长度为1，则直接解析JSON数据
                                _this.waitingOrders = responseDataArray[0];
                            } else {
                                // 如果数组长度大于1，则将整理后的数据添加到tableData中
                                _this.waitingOrders = _this.waitingOrders.concat(responseDataArray);
                            }}
                        _this.getTotalCountOfAllUnGetOrder();
                    })
                    .catch(error => {
                        console.error('Error fetching data', error);
                    });


            },
            // 获取全部订单数据
            fetchAllOrders() {
                var _this=this
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/selectAllOrder?" +"CurrentPage="+this.currentPage+"&PageSize="+this.pageSize+"" )
                    .then(resp => {
                        _this.allOrders = [];
                        if (typeof resp.data === 'object' && resp.data!== null){
                            _this.allOrders.push(resp.data);}else{
                            // 使用split方法将字符串按照"}"分割成数组
                            const responseDataArray = resp.data.split('}').map(item => {
                                if (item) return JSON.parse(item + '}');
                                else return null;
                            }).filter(item => item !== null);

                            // 根据数组长度判断是否为单个对象或多个对象组成的数组
                            if (responseDataArray.length === 1) {
                                // 如果数组长度为1，则直接解析JSON数据
                                _this.allOrders = responseDataArray[0];
                            } else {
                                // 如果数组长度大于1，则将整理后的数据添加到tableData中
                                _this.allOrders = _this.allOrders.concat(responseDataArray);
                            }}
                        _this.getTotalCountOfAllOrder();
                    })
                    .catch(error => {
                        console.error('Error fetching data', error);
                    });
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
                this.activeIndex = key;
                this.currentPage=1;
                if (this.activeIndex === '1-1') {
                    this.getTotalCountOfAllUnGetOrder();
                    this.fetchWaitingOrders();
                } else if (this.activeIndex === '1-2') {
                    this.getTotalCountOfAllOrder();
                    this.fetchAllOrders();
                }
            },
            goToChange() {
                window.location.href = 'login.html';
            },
            getTotalCountOfAllOrder(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/getTotalCountOfAllOrder" )
                    .then((resp) => {
                       _this.totalCount=resp.data;
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            getTotalCountOfAllUnGetOrder(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/getTotalCountOfAllUnGetOrder" )
                    .then((resp) => {
                        _this.totalCount=resp.data;
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            selectUserInfo(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/User/selectUserInfo" )
                    .then((resp) => {
                        _this.user=resp.data;
                        _this.sendOrder.fromUserId=_this.user.id;
                        _this.sendOrder.receiveAddress=_this.user.defaultSendAddress;
                        _this.sendOrder.sendAddress=_this.user.defaultGetAddress;
                        console.log(_this.user.imagPath);
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            openDialog(row) {
                // 假设你的数据对象名为 rowData，其中包含 pickupCode 字段
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Occupy/selectGetWordAndReceiveAddress?onlyId="+row.onlyId )
                    .then((resp) => {
                        console.log(resp.data);
                        if(resp.data===null){
                            console.log(666666666)
                            this.$message({
                                message: '顾客不要着急，快递小哥正在骑马来的路上',
                                type: 'warning'
                            });
                        }else{
                            console.log(55555)
                        _this.receiveAddressAndGetWord=resp.data;
                        console.log(_this.user.imagPath);
                            this.dialogVisible = true;

                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            closeDialog() {
                this.dialogVisible = false;
            },
            onSubmit() {
                var _this=this;
                axios({
                    method:"post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/Order/selectOrdersByOnlyId?onlyId="+_this.order.onlyId,
                    data:_this.order,
                }).then(resp => {
                    _this.selectResultOrder=[];
                    _this.selectResultOrder.push(resp.data);
                    console.log(resp.data)
                    _this.dialogTableVisible=true;

                })
            },
            startSend(){
                var _this = this;
                console.error(_this.sendOrder);

                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/User/addOrder?check=" + _this.checked, // 确保URL路径正确
                    data: _this.sendOrder,


                })
                    .then((resp) => {
                        if (resp.data === "success") {
                            this.$message({
                                message: '恭喜你。成功寄出',
                                type: 'success'
                            });
                            this.dialogFormVisible = false;
                            _this.sendOrder.goodInfo='';
                            _this.selectUserInfo();
                            _this.checked=false;
                            _this.selectAllUnSendOrderByCondition();
                            _this.selectAllSendingOrderByCondition();
                        }else {
                            this.$message({
                                message: '抱歉，您的余额不足，请充值^_^',
                                type: 'warning'
                            });
                            this.dialogFormVisible = false;
                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            startGet(){
                var _this = this;

                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/Order/getGood" , // 确保URL路径正确
                    data: _this.occupy,


                })
                    .then((resp) => {
                         if(resp.data=== "???"){
                            this.$message({
                                message: '顾客上帝，不要自娱自乐@_@',
                                type: 'warning'
                            });
                            this.getDialogFromVisible = false;
                        }else if(resp.data==="you are pool"){
                             this.$message({
                                 message: '有滞留过长收费。请充值',
                                 type: 'warning'
                             });
                             this.getDialogFromVisible = false;
                         } else if(resp.data=== "can not find"){
                            this.$message({
                                message: '未找到，请检查您的输入',
                                type: 'warning'
                            });
                        }else if(resp.data==="The order has accept"){
                            this.$message({
                                message: '顾客，您已经取件了哦',
                                type: 'warning'
                            });
                            this.getDialogFromVisible = false;
                        }else  {
                             _this.requireMoney=resp.data;
                            this.$message({
                                message: '恭喜你。成功取出，祝您天天开心哦，亲（^_^）,取出花费了'+_this.requireMoney+'元',
                                type: 'success'
                            });
                            this.getDialogFromVisible = false;
                            _this.occupy.getWord='';
                            _this.occupy.getAddress='',
                                _this.fetchAllOrders();
                            _this.fetchWaitingOrders();
                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            openPage(){
                this.selectCountOfCoupon();
                this.dialogFormVisible=true;
            },
            startToGet(){
                this.getDialogFromVisible=true;

            },


            /**就是用于进行修改用户操作的openDialog**/


            startUpdate(){
                this.updateDialog=true;
            },
            Update(){
                var _this = this;

                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/User/updateInfoOfUser" , // 确保URL路径正确
                    data: _this.user,

                })
                    .then((resp) => {
                        if (resp.data === "success") {
                            this.$message({
                                message: '恭喜你。成功修改',
                                type: 'success'
                            });
                            this.updateDialog = false;
                            _this.selectUserInfo();
                            _this.fetchAllOrders();
                            _this.fetchWaitingOrders();
                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },







            getTotalCountOfAllSendOrder(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/getCountOfSendingOrders" )
                    .then((resp) => {
                        _this.totalCount2=resp.data;
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            getTotalCountOfAllUnSendOrder(){
                var _this=this;
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/getCountOfUnSendingOrders" )
                    .then((resp) => {
                        _this.totalCount2=resp.data;
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },

            handleSizeChange2(val) {
                this.pageSize2 = val;
            },
            handleCurrentChange2(val) {
                this.currentPage2 = val;
                if (this.Index === '1-1') {
                    this.selectAllUnSendOrderByCondition();
                } else if (this.Index === '1-2') {
                    this.selectAllSendingOrderByCondition();
                }

            },

            // 获取待取订单数据
            selectAllUnSendOrderByCondition() {

                var _this=this
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/selectAllUnSendOrderByCondition?"+"CurrentPage="+this.currentPage2+"&PageSize="+this.pageSize2+""  )
                    .then(resp => {
                        _this.allUnSendOrders = [];
                        if (typeof resp.data === 'object' && resp.data!== null){
                            _this.allUnSendOrders.push(resp.data);}else{
                            // 使用split方法将字符串按照"}"分割成数组
                            const responseDataArray = resp.data.split('}').map(item => {
                                if (item) return JSON.parse(item + '}');
                                else return null;
                            }).filter(item => item !== null);

                            // 根据数组长度判断是否为单个对象或多个对象组成的数组
                            if (responseDataArray.length === 1) {
                                // 如果数组长度为1，则直接解析JSON数据
                                _this.allUnSendOrders = responseDataArray[0];
                            } else {
                                // 如果数组长度大于1，则将整理后的数据添加到tableData中
                                _this.allUnSendOrders = _this.allUnSendOrders.concat(responseDataArray);
                            }}
                        _this.getTotalCountOfAllUnSendOrder();
                    })
                    .catch(error => {
                        console.error('Error fetching data', error);
                    });


            },


            handleSelect2(key, keyPath) {
                console.log(key, keyPath);
                this.Index = key;
                this.currentPage2=1;
                if (this.Index === '1-1') {
                    this.getTotalCountOfAllUnSendOrder();
                    this.selectAllUnSendOrderByCondition();
                } else if (this.Index === '1-2') {
                    this.getTotalCountOfAllSendOrder();
                    this.selectAllSendingOrderByCondition();
                }
            },
            // 获取全部订单数据
            selectAllSendingOrderByCondition() {
                var _this=this
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Order/selectAllSendingOrderByCondition?" +"CurrentPage="+this.currentPage2+"&PageSize="+this.pageSize2+"" )
                    .then(resp => {
                        _this.allSendOrders = [];
                        if (typeof resp.data === 'object' && resp.data!== null){
                            _this.allSendOrders.push(resp.data);}else{
                            // 使用split方法将字符串按照"}"分割成数组
                            const responseDataArray = resp.data.split('}').map(item => {
                                if (item) return JSON.parse(item + '}');
                                else return null;
                            }).filter(item => item !== null);

                            // 根据数组长度判断是否为单个对象或多个对象组成的数组
                            if (responseDataArray.length === 1) {
                                // 如果数组长度为1，则直接解析JSON数据
                                _this.allSendOrders = responseDataArray[0];
                            } else {
                                // 如果数组长度大于1，则将整理后的数据添加到tableData中
                                _this.allSendOrders = _this.allSendOrders.concat(responseDataArray);
                            }}
                        _this.getTotalCountOfAllSendOrder();
                    })
                    .catch(error => {
                        console.error('Error fetching data', error);
                    });
            },
            addMoney(){
                this.moneyDialog=true;
            },
            addLittleMoney(){
                var _this = this;

                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/User/addLittleMoney" ,
                })
                    .then((resp) => {
                        if (resp.data === "success") {
                            this.$message({
                                message: '谢谢惠顾(!_!)',
                                type: 'success'
                            });
                            this.moneyDialog = false;
                            _this.selectUserInfo()
                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            addMuchMoney(){
                var _this = this;
                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/User/addMuchMoney" ,
                })
                    .then((resp) => {
                        if (resp.data === "success") {
                            this.$message({
                                message: '谢谢惠顾(!_!)',
                                type: 'success'
                            });
                            this.moneyDialog = false;
                            _this.selectUserInfo()
                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            startToTalk(row){
                if(row.transportId===0 ){
                    this.$message({
                        message: '等待派送ing~',
                        type: 'error'
                    });
                }else{
                window.location.href = 'main.html?id='+row.transportId;}
            },
            getCoupon(){
                this.couponDialog=true;
            },
            HaveALook(){
                if(this.hasCoupon===true){
                    this.onlyIdDialog=true;
                }else{
                    const _this = this;
                    axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/Coupon/generateCoupon" )
                        .then((resp) => {
                            _this.couponOnlyId=resp.data;
                            this.couponDialog=false;
                            _this.hasCoupon=true;
                        })
                        .catch((error) => {
                            console.error(error);
                        });
                }

            },
            stopLook(){
                this.onlyIdDialog=false;
            },
            addCoupon(){
                var _this = this;

                axios({
                    method: "post",
                    url: "http://localhost:8080/ChenXufeng_Fengchao_System/Coupon/addCoupon?onlyId="+_this.onlyIdOfOthers ,
                })
                    .then((resp) => {
                        if (resp.data === "success") {
                            this.$message({
                                message: '成功',
                                type: 'success'
                            });
                            this.couponDialog=false;
                        }else if(resp.data==="error"){
                            this.$message({
                                message: '未找到对应的用户，请检查您的输入',
                                type: 'warning'
                            });
                        }else{
                            this.$message({
                                message: '您已经助力过了',
                                type: 'warning'
                            });
                            this.couponDialog=false;

                        }
                    })
                    .catch((error) => {
                        console.error(error);
                    });
            },
            OpenMyNew(){
                this.getNew();
                this.newBoxDialog=true;
            },
            getNew(){
                var _this=this
                axios.get("http://localhost:8080/ChenXufeng_Fengchao_System/New/selectAllNew"  )
                    .then(resp => {
                        _this.newBox = [];
                        if (typeof resp.data === 'object' && resp.data!== null){
                            _this.newBox.push(resp.data);}else{
                            // 使用split方法将字符串按照"}"分割成数组
                            const responseDataArray = resp.data.split('}').map(item => {
                                if (item) return JSON.parse(item + '}');
                                else return null;
                            }).filter(item => item !== null);

                            // 根据数组长度判断是否为单个对象或多个对象组成的数组
                            if (responseDataArray.length === 1) {
                                // 如果数组长度为1，则直接解析JSON数据
                                _this.newBox = responseDataArray[0];
                            } else {
                                // 如果数组长度大于1，则将整理后的数据添加到tableData中
                                _this.newBox = _this.newBox.concat(responseDataArray);
                            }}

                        })
                    .catch(error => {
                        console.error('Error fetching data', error);
                    });
            },
        },

    });
</script>
<style scoped>
    .user-profile {
        margin: 20px;
    }
    .avatar-uploader {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 120px;
        height: 120px;
        border-radius: 50%;
        overflow: hidden;
        background-color: #f4f4f4;
        position: relative;
    }
    .avatar {
        width: 100%;
        height: 100%;
    }
</style>
</body>
</html>
